// pages/xiaoxi/xiaoxi.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hzxx: [],
    listxx: 0, // 0全部，1未读，2已读
    pageNum: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.httpRequest()
  },
  // 发送网络请求
  httpRequest(){
    let _data = wx.getStorageSync("_data")
    let _this = this
    wx.request({
      url: 'https://dl.ctrecruit.cn/login.php',
      data: {
        dlID: _data.dlID,
        xx: _data.dlqb,
        listxx: _this.data.listxx,
        pageNum: _this.data.pageNum
      },
      method: 'POST',
      header:{
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res){
        let Result = res.data
        _this.setData({
          hzxx: Result.hzxx.hzxx,
        })
      }
    })
  },
  // 进入消息详情
  XiaoxiDetail(e){
    let _data = wx.getStorageSync("_data")
    let id = e.currentTarget.dataset.id
    let pid = e.currentTarget.dataset.pid
    let dlqb = _data.dlqb
    let _index = 0
    this.data.hzxx.forEach(function(i, index){
      if(i.id == id){
        _index = index
        return;
      }
    })
    this.data.hzxx[_index].tongzhi = '0'
    this.setData({
      hzxx: this.data.hzxx
    })
    wx.navigateTo({
      url: `/pages/xiaoxi-detail/xiaoxi-detail?id=${id}&pid=${pid}&dlqb=${dlqb}`
    })
  },
  // 已读未读切换
  radioChange(e){
    this.setData({
      listxx: e.detail.value
    })
    this.httpRequest()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let _data = wx.getStorageSync("_data")
    let _this = this
    wx.request({
      url: 'https://dl.ctrecruit.cn/login.php',
      data: {
        dlID: _data.dlID,
        xx: _data.dlqb,
        listxx: _this.data.listxx,
        pageNum: _this.data.pageNum
      },
      method: 'POST',
      header:{
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res){
        let wdnum = res.data.remind_dlw
        if(wdnum == '0'){
          wx.removeTabBarBadge({
            index: 1
          })
        } else {
          wx.setTabBarBadge({
            index: 1,
            text: wdnum
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})